{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a9852b22-170b-47f0-9b5c-70de4c4b7fb1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "y.shapr= (4, 26, 26, 2)\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "input=(4,28,28,3)\n",
    "x=tf.random.normal(input)\n",
    "y=tf.keras.layers.Conv2D(2,3,strides=(1,1),padding='VALID',activation='relu',input_shape=input[1:])(x)\n",
    "print(\"y.shapr=\",y.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "5edbbbe4-0237-4c30-b9b0-f8c1c2691509",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "MaxPool(x).numpy()=\n",
      " [[[[3]\n",
      "   [4]]\n",
      "\n",
      "  [[4]\n",
      "   [3]]]]\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "input=tf.constant([[1,1,0,1],[3,-3,4,2],[2,0,1,3],[4,2,-1,0]])\n",
    "x=tf.reshape(input,[1,4,4,1])\n",
    "MaxPool=tf.keras.layers.MaxPool2D(pool_size=(2,2),strides=(2,2),padding='VALID')\n",
    "print(\"MaxPool(x).numpy()=\\n\",MaxPool(x).numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6c4c82e6-a086-458c-b6d4-8f4da084acca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AveragePooling(x).numpy()=\n",
      " [[[[0.5 ]\n",
      "   [1.75]]\n",
      "\n",
      "  [[2.  ]\n",
      "   [0.75]]]]\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "input=tf.constant([[1,1,0,1],[3,-3,4,2],[2,0,1,3],[4,2,-1,0]],dtype=tf.float32)\n",
    "x=tf.reshape(input,[1,4,4,1])\n",
    "AveragePooling=tf.keras.layers.AveragePooling2D(pool_size=(2,2),strides=(2,2),padding='VALID')\n",
    "print(\"AveragePooling(x).numpy()=\\n\",AveragePooling(x).numpy())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "200f7831-3367-45ef-a206-8c0860a2c46b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
